//--- OBJECT WRITE BEGIN ---
new GuiChunkedBitmapCtrl(StartMissionGui) {
   Profile = "GuiContentProfile";
   HorizSizing = "width";
   VertSizing = "height";
   position = "0 0";
   Extent = "640 480";
   MinExtent = "8 8";
   Visible = "1";
   bitmap = "./lockerroom.png";
   useVariable = "0";
   tile = "0";
      helpTag = "0";

   new GuiTextListCtrl(SM_missionList) {
      Profile = "GuiTextArrayProfile";
      HorizSizing = "right";
      VertSizing = "bottom";
      position = "2 2";
      Extent = "80 8";
      MinExtent = "8 8";
      Visible = "0";
      enumerate = "0";
      resizeCell = "1";
      columns = "0";
      fitParentWidth = "1";
      clipColumnText = "0";
         noDuplicates = "False";
         helpTag = "0";
   };
   new GuiBitmapButtonCtrl() {
      Profile = "GuiDefaultProfile";
      HorizSizing = "right";
      VertSizing = "bottom";
      position = "129 299";
      Extent = "71 26";
      MinExtent = "8 2";
      Visible = "1";
      Command = "SM_StartMission();";
      text = "mission1";
      groupNum = "-1";
      buttonType = "PushButton";
      bitmap = "~/client/menu/main/JockMisPic";
   };
   new GuiBitmapButtonCtrl() {
      Profile = "GuiDefaultProfile";
      HorizSizing = "right";
      VertSizing = "bottom";
      position = "15 303";
      Extent = "73 37";
      MinExtent = "8 2";
      Visible = "1";
      Command = "Canvas.setContent(mainmenuGui);";
      text = "back";
      groupNum = "-1";
      buttonType = "PushButton";
      bitmap = "~/client/menu/common/back";
   };
   new GuiBitmapButtonCtrl() {
      Profile = "GuiDefaultProfile";
      HorizSizing = "right";
      VertSizing = "bottom";
      position = "686 299";
      Extent = "100 61";
      MinExtent = "8 2";
      Visible = "1";
      Command = "Canvas.setContent(shoproomgui);";
      text = "Button";
      groupNum = "-1";
      buttonType = "PushButton";
      bitmap = "~/client/menu/main/shop";
   };
   new GuiBitmapButtonCtrl() {
      Profile = "GuiDefaultProfile";
      HorizSizing = "right";
      VertSizing = "bottom";
      position = "578 307";
      Extent = "74 25";
      MinExtent = "8 2";
      Visible = "1";
      Command = "SM_StartMission();";
      text = "mission1";
      groupNum = "-1";
      buttonType = "PushButton";
      bitmap = "~/client/menu/main/GeekMisPic";
   };
   new GuiBitmapCtrl() {
      Profile = "GuiDefaultProfile";
      HorizSizing = "right";
      VertSizing = "bottom";
      position = "130 371";
      Extent = "94 125";
      MinExtent = "8 2";
      Visible = "1";
      bitmap = "~/client/menu/main/jock.png";
      wrap = "0";
   };
   new GuiBitmapCtrl() {
      Profile = "GuiDefaultProfile";
      HorizSizing = "right";
      VertSizing = "bottom";
      position = "563 370";
      Extent = "102 126";
      MinExtent = "8 2";
      Visible = "1";
      bitmap = "~/client/menu/main/cool.png";
      wrap = "0";
   };
};
//--- OBJECT WRITE END ---


//----------------------------------------
function SM_StartMission()
{
   %id = SM_missionList.getSelectedId();
   %mission = getField(SM_missionList.getRowTextById(%id), 1);

   if ($pref::HostMultiPlayer)
      %serverType = "MultiPlayer";
   else
      %serverType = "SinglePlayer";

   createServer(%serverType, %mission);
   %conn = new GameConnection(ServerConnection);
   RootGroup.add(ServerConnection);
   %conn.setConnectArgs($pref::Player::Name);
   %conn.setJoinPassword($Client::Password);
   %conn.connectLocal();
}


//----------------------------------------
function startMissionGui::onWake()
{
   SM_missionList.clear();
   %i = 0;
   for(%file = findFirstFile($Server::MissionFileSpec); %file !$= ""; %file = findNextFile($Server::MissionFileSpec))  
      if (strStr(%file, "/CVS/") == -1)
         SM_missionList.addRow(%i++, getMissionDisplayName(%file) @ "\t" @ %file );
   SM_missionList.sort(0);
   SM_missionList.setSelectedRow(0);
   SM_missionList.scrollVisible(0);
}   


//----------------------------------------
function getMissionDisplayName( %missionFile ) 
{
   %file = new FileObject();
   
   %MissionInfoObject = "";
   
   if ( %file.openForRead( %missionFile ) ) {
		%inInfoBlock = false;
		
		while ( !%file.isEOF() ) {
			%line = %file.readLine();
			%line = trim( %line );
			
			if( %line $= "new ScriptObject(MissionInfo) {" )
				%inInfoBlock = true;
			else if( %inInfoBlock && %line $= "};" ) {
				%inInfoBlock = false;
				%MissionInfoObject = %MissionInfoObject @ %line; 
				break;
			}
			
			if( %inInfoBlock )
			   %MissionInfoObject = %MissionInfoObject @ %line @ " "; 	
		}
		
		%file.close();
	}
	%MissionInfoObject = "%MissionInfoObject = " @ %MissionInfoObject;
	eval( %MissionInfoObject );
	
   %file.delete();

   if( %MissionInfoObject.name !$= "" )
      return %MissionInfoObject.name;
   else
      return fileBase(%missionFile); 
}

